package com.lzc.springboot.controller;

import com.lzc.springboot.domain.Farmer;
import com.lzc.springboot.domain.Question;
import com.lzc.springboot.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/question")
public class QuestionController {

  @Autowired
  private QuestionService questionService;

  /**
   * 根据农户ID查询未解决问题
   * @param fid
   * @return
   */
  @RequestMapping("/findAllUnsolved")
  public Question[] findAllUnsolved(int fid){
    return questionService.findAllUnsolved(fid);
  }

  /**
   * 根据农户ID查询已经解决问题
   * @param fid
   * @return
   */
  @RequestMapping("/findAllSolved")
  public Question[] findAllSolved(int fid){
    return questionService.findAllSolved(fid);
  }

  /**
   * 根据ID删除问题
   * @param id
   */
  @RequestMapping("/delQuestionById")
  public void delQuestionById(int id){
    questionService.delQuestionById(id);
  }

  /**
   * 添加问题
   * @param question
   */
  @RequestMapping("/addQuestion")
  public void addQuestion(@RequestBody Question question){
    questionService.addQuestion(question);
  }

  /**
   * 根据专家ID查询未解决的问题
   * @param eid
   * @return
   */
  @RequestMapping(value = "/findAllUnsolvedByEid",method = RequestMethod.GET)
  public Question[] findAllUnsolvedByEid(@RequestParam("eid") int eid){
    return questionService.findAllUnsolvedByEid(eid);
  }

  /**
   * 根据专家ID查询已经解决的问题
   * @param eid
   * @return
   */
  @RequestMapping(value = "/findAllSolvedByEid",method = RequestMethod.GET)
  public Question[] findAllSolvedByEid(@RequestParam("eid") int eid){
    return questionService.findAllSolvedByEid(eid);
  }

  /**
   * 问题回复
   * @param question
   */
  @RequestMapping("/answerQuestion")
  public void answerQuestion(@RequestBody Question question){
    questionService.answerQuestion(question);
  }

  /**
   * 根据用户输入内容查询问题
   * @param farmer
   * @return
   */
  @RequestMapping("/findUnresolvedQuestionByText")
  public Question[] findUnresolvedQuestionByText(@RequestBody Farmer farmer){
    return questionService.findUnresolvedQuestionByText(farmer);
  }

  /**
   * 根据用户输入内容查询问题
   * @param farmer
   * @return
   */
  @RequestMapping("/findSolvedQuestionByText")
  public Question[] findSolvedQuestionByText(@RequestBody Farmer farmer){
    return questionService.findSolvedQuestionByText(farmer);
  }
}
